/**
 * 
 */
package com.actor.java;

import java.io.IOException;
import java.io.StringWriter;

import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

import com.bean.ResultBean;
import com.util.FileUtil;
import com.util.StringUitl;

/**
 * @author Ltz
 */
public class ManageDaoActor {

	/**
	 * 
	 */
	public ManageDaoActor(ResultBean resultBean) {
		try {
			Velocity.init();
		} catch (Exception e) {
			System.out.println("创建dao模版失败" + e);
			return;
		}
        String tableName=resultBean.getTableBean().getTableName().split("_")[1];
        String objectComment = resultBean.getTableBean().getTableComment();
        String objectName = StringUitl.CaptureName(tableName);
        String objectParam= tableName;
        String packagePath = "shop.services.manage." + tableName+".dao";
        VelocityContext context = new VelocityContext();
        context.put("packagePath", packagePath);
        context.put("crateTime", StringUitl.GetNowDate());
        context.put("objectName", objectName);
        context.put("objectParam", objectParam);
        context.put("objectComment", objectComment.replaceAll("表", ""));
        StringWriter w = new StringWriter();

		try {
			Velocity.mergeTemplate("src/main/java/com/template/java/managedao.vm", "UTF-8", context, w);
		} catch (Exception e) {
			System.out.println("模版匹配失败: " + e);
		}

		try {
			FileUtil.creatTxtFile(packagePath, objectName + "Dao", ".java", w.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
